<?php

Route::namespace('Api')->prefix('v1')->group(function () {
    Route::post('/login/wechatMiniProgram', 'LoginController@wechatMiniProgram');

    Route::middleware('auth:api')->group(function () {
        Route::post('/user', 'UserController@modify');
        Route::get('/user', 'UserController@show');

        Route::get('/group', 'GroupController@list');
        Route::post('/group', 'GroupController@create');
        Route::get('/group/{group}', 'GroupController@show')->name('group');
        Route::post('/group/{group}', 'GroupController@modify')->middleware('can:update,group')->name('group_modify');
        Route::get('/group/{group}/users', 'GroupController@users')->name('group_users');
        Route::post('/group/{group}/users', 'GroupController@removeUser')->name('group_remove_users');
        Route::get('/group/{group}/users/leaderboard', 'GroupController@usersLeaderboard')->name('group_users_leaderboard');
        Route::post('/group/{group}/join', 'GroupController@join')->middleware('can:join,group');
        Route::delete('/group/{group}', 'GroupController@dissolution')
            ->middleware('can:update,group')
            ->name('group_dissolution');

        Route::get('/quiz', 'QuizController@list');
        Route::get('/quiz/group', 'QuizController@canCreateQuizGroups');
        Route::get('/quiz/{quiz}', 'QuizController@show')->name('quiz');
        Route::get('/quiz/{quiz}/player', 'QuizController@player');
        Route::get('/group/{group}/quizzes', 'QuizController@listInGroup')->name('group_quizzes');
        Route::get('/quiz/{quiz}/result', 'QuizController@result')->name('quiz_result');
        Route::post('/quiz', 'QuizController@create');
        Route::delete('/quiz/{quiz}', 'QuizController@close')->middleware('can:close,quiz')->name('quiz_close');
        Route::post('/quiz/{quiz}', 'QuizController@modify')->middleware('can:update,quiz');

        Route::post('/quiz/{quiz}/item', 'QuizItemController@create')->middleware('can:update,quiz');
        Route::post('/quiz/item/{quizItem}', 'QuizItemController@modify')->middleware('can:update,quizItem');
        Route::delete('/quiz/item/{quizItem}', 'QuizItemController@close')->middleware('can:update,quizItem');

        Route::post('/quiz/{quizItem}/bet', 'PlayController@bet')->middleware('can:play,quizItem');
        Route::post('/quiz/{quiz}/announce', 'PlayController@announce')->middleware('can:update,quiz')->name('announce');

        Route::get('/search/flag', 'SearchController@flag');
        Route::get('/setting/MiniProgramQrcode', 'SettingController@MiniProgramQrcode');
    });
});
